<template>
  <a-spin :spinning="confirmLoading">

    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <!--主表区域 -->
      <a-tab-pane tab="生产管理流程" :key="refKeys[0]" :forceRender="true" :class="'jeecg-tabs-top'" :animated="false">
        <a-form-model ref="form" :model="model" :rules="validatorRules">
          <a-row>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="流程状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmStatus">
                <a-input v-model="model.bpmStatus" placeholder="请输入流程状态" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="任务编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskId">
                <a-input v-model="model.taskId" placeholder="请输入任务编号" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="任务名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskName">
                <a-input v-model="model.taskName" placeholder="请输入任务名称" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="任务内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskNeirong">
                <a-input v-model="model.taskNeirong" placeholder="请输入任务内容" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dingdanBianhao">
                <a-input v-model="model.dingdanBianhao" placeholder="请输入订单编号" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dingdanKehu">
                <a-input v-model="model.dingdanKehu" placeholder="请输入客户名称" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="模型件数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dingdanShuliang">
                <a-input v-model="model.dingdanShuliang" placeholder="请输入模型件数" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="模型重克" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dingdanMoxingzhongliang">
                <a-input v-model="model.dingdanMoxingzhongliang" placeholder="请输入模型重克" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="下单时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dingdanXiadanshijian">
                <a-input v-model="model.dingdanXiadanshijian" placeholder="请输入下单时间" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="接单员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dingdanJiedanyuan">
                <a-input v-model="model.dingdanJiedanyuan" placeholder="请输入接单员" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="订单要求" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dingdanYaoqiu">
                <a-input v-model="model.dingdanYaoqiu" placeholder="请输入订单要求" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="模型图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dingdanTupian">
                <a-input v-model="model.dingdanTupian" placeholder="请输入模型图片" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="货款状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dingdanHuokuan">
                <a-input v-model="model.dingdanHuokuan" placeholder="请输入货款状态" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="发货方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dingdanFahuofangshi">
                <a-input v-model="model.dingdanFahuofangshi" placeholder="请输入发货方式" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xs="24" :sm="12">
              <a-form-model-item label="订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dingdanZhuangtai">
                <a-input v-model="model.dingdanZhuangtai" placeholder="请输入订单状态" ></a-input>
              </a-form-model-item>
            </a-col>

          </a-row>
        </a-form-model>

      </a-tab-pane>
      <!--子表单区域 -->
    </a-tabs>

  </a-spin>
</template>

<script>

import { FormTypes,getRefPromise } from '@/utils/JEditableTableUtil'
import { JEditableTableModelMixin } from '@/mixins/JEditableTableModelMixin'
import { validateDuplicateValue } from '@/utils/util'
import { VALIDATE_NO_PASSED, validateFormModelAndTables } from '@/utils/JEditableTableUtil'
import { getAction } from '@api/manage'

export default {
  name: 'TableDayinForm',
  props: ['formData'],
  mixins: [JEditableTableModelMixin],
  components: {
  },
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 3 },
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 20 },
      },
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 1,
      model:{
      },
      validatorRules: {
      },
      refKeys: ['tableDayin',],
      tableKeys:[],
      activeKey: 'tableDayin',
      url: {
        add: "/dayin/tableDayin/add",
        edit: "/dayin/tableDayin/edit",
        list: '/dayin/tableDayin/queryById'
      }
    }
  },
  created() {
    console.log("form start");
    console.log("formdata",this.formData);
    //通过借款单ID，查询借款单
    var params = {id:this.formData.vars.id};
    getAction(this.url.list,params).then((res)=>{
      if(res.success){
        console.log("获取借款单信息",res);
        this.edit (res.result);
        //-------------------------------------------------------------------------------------------------
        //通过出差单号，查询出差单
        /*var params2 = {tripApplyNo: res.result.tripApplyNo};//查询条件
        getAction(this.url.queryTripByApplyNo,params2).then((res)=>{
          if(res.success){
            console.log("获取出差单信息",res);
            this.detailStrip (res.result);
          }
        });*/
        //-------------------------------------------------------------------------------------------------
      }
    })
  },
  methods: {
    getAllTable() {
      return new Promise(resolve => {
        resolve([]);
      })
    },
    /** 调用完edit()方法之后会自动调用此方法 */
    editAfter() {
      this.$nextTick(() => {
      })
      // 加载子表数据
      if (this.model.id) {
        let params = { id: this.model.id }
      }
    },
    //校验所有一对一子表表单
    validateSubForm(allValues){
      return new Promise((resolve,reject)=>{
        Promise.all([
        ]).then(() => {
          resolve(allValues)
        }).catch(e => {
          reject(e)
        })
      })
    },
    /** 整理成formData */
    classifyIntoFormData(allValues) {
      let main = Object.assign(this.model, allValues.formValue)
      return {
        ...main, // 展开
      }
    },
    /** 确定按钮点击事件 */
    handleOk() {
      /** 触发表单验证 */
      this.getAllTable().then(tables => {
        return validateFormModelAndTables(this.$refs.form,this.model, tables)
      }).then(allValues => {
        /** 一次性验证一对一的所有子表 */
        return this.validateSubForm(allValues)
      }).then(allValues => {
        if (typeof this.classifyIntoFormData !== 'function') {
          throw this.throwNotFunction('classifyIntoFormData')
        }
        console.log("this.classifyIntoFormData",typeof this.classifyIntoFormData)
        let formData = this.classifyIntoFormData(allValues)

        // 发起请求
        return this.request(formData)
      }).catch(e => {
        if (e.error === VALIDATE_NO_PASSED) {
          // 如果有未通过表单验证的子表，就自动跳转到它所在的tab
          this.activeKey = e.index == null ? this.refKeys[0] : this.refKeys[e.index+1]
        } else {
          console.error(e)
        }
      })
    },
    validateError(msg){
      this.$message.error(msg)
    },
    close() {
      this.visible = false
      this.$emit('close')
      this.$refs.form.clearValidate();
    },

  }
}
</script>

<style scoped>
/** tab panel 中有下拉框/日期 这类带下拉效果的，需要加此样式 */
/deep/ .jeecg-tabs-top {
  overflow: visible;
}
</style>